package com.zijie.hosptal.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijie.hosptal.pojo.po.DoctorSchedules;
import com.zijie.hosptal.pojo.po.Reserve;
import com.zijie.hosptal.pojo.vo.DoctorSchedulesVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface DoctorSchedulesMapper extends BaseMapper<DoctorSchedules> {


     Page<DoctorSchedulesVO> findList(Page<DoctorSchedulesVO> schedulePage, DoctorSchedules doctorSchedules);

     DoctorSchedules selectById(Integer id);

     List<DoctorSchedules> getAll();

     @Select("select id,name,doctor_id,total_slots,status,start_time from doctor_schedules where id=#{id}")
    DoctorSchedules getById(Integer id);

     @Select("select count(1) from doctor_schedules")
    Integer getDoctorSchedulesTotal();

    Boolean selectByReserTime(Reserve reserve);


    void updateByReserve(DoctorSchedules doctorSchedules);


    @Select("select id,department_id from doctor_schedules where date(start_time)=date(#{startTime}) and department_id=#{departmentId} limit  1")
    DoctorSchedules selectDoctorSchedule(DoctorSchedules doctorSchedules);

    @Select("select id,doctor_id from doctor_schedules where doctor_id=#{doctorId} and date(start_time)=date(#{startTime}) limit 1")
    DoctorSchedules selectIsDoctor(DoctorSchedules doctorSchedules);

    void updateStatus();

    void updateStatus5();

    @Update("update doctor_schedules set status=#{status} where id=#{id}")
    void updateStatusById(DoctorSchedules doctorSchedules);


    @Select("select id from doctor_schedules where doctor_id=#{id} and status in(1,4) limit 1")
    Integer selectNamalByDoctorId(Integer id);

    @Select("select id from doctor_schedules where department_id= #{id} and status in(1,2,4) limit 1")
    Integer selectNamalByDepartmentId(Integer id);
}
